#include <stdio.h>

#include "tlib_ip_limit.h"

int main(int argc ,char *argv[])
{
	int iKey,iBlockIndex;
	char sErrMsg[200];
	int iRetCode;
	int iRefresh;
	
	TLIB_IP_ACCESS_ENTRY *pstEntry;
	int i,iMaxAccessCount,iLimitTimeInterval,iRecalTimeInterval,iAccessCount;
	
	if (argc<8){
		printf("Usage %s key ip MaxAccessCount LimitTimeInterval RecalTimeInterval AccessCount Refresh \n",argv[0]);
		return -1;
	}
	
	iKey=atoi(argv[1]);
	if (iKey==0){
		printf("Invlalid key\n");
		return -1;
		
	}	
	
	iMaxAccessCount=atoi(argv[3]);
	iLimitTimeInterval=atoi(argv[4]);
	iRecalTimeInterval=atoi(argv[5]);
	iAccessCount=atoi(argv[6]);
	iRefresh=atoi(argv[7]);
	
	iRetCode=TLib_IP_Limit_Init(iKey,iLimitTimeInterval,iRecalTimeInterval,iMaxAccessCount,iRefresh,sErrMsg);
	if (iRetCode!=0){
		printf("%s\n",sErrMsg);
		return -1;
	}	
	
	for (i=0;i<iAccessCount;i++){
		iRetCode=TLib_IP_Limit_Access(argv[2],sErrMsg);
		if (iRetCode<0){
			printf("%s\n",sErrMsg);
			return -1;
			
		}else if (iRetCode==1){
			printf("%s access has over the MaxCount %d \n",argv[2],iMaxAccessCount);
			return -1;			
		}			
	}
	
	
	
	return 0;
}
